<template>
	<view class="my_container">
		<view class="bg">
			<image :src="myBgSrc" class="wdbg" mode="cover"></image>
			<view  class="da" v-if="iosUpAppStore">
				<image :src="myBgSrc1" class="hei" mode="cover"></image>
				<image src="../../static/my/vip.png" class="vip" mode=""></image>
				<view v-if="!huiyuan">
					<view class="kai">
						开通会员，享更多特殊权限
					</view>
					<view @click="vip" class="liji">
						立即开通
					</view>
				</view>
				<view v-if="huiyuan">
					<view class="kai">
						开通时长：{{userinfo.vip_time_text}}
					</view>
					<view @click="vip" class="liji">
						立即续费
					</view>
				</view>
			</view>
			<view class="tu">
				<view class="tu_left">
					<image @click="user_xx" :src="userinfo.avatar || logo" class="avatar" mode=""></image>
				</view>
				<view v-if="!isLogin" class="tu_center" style="padding-top: 0;">
					<view @click="denglu" class="wen" style="line-height: 130rpx;">
						未登录
					</view>
				</view>
				<view v-if="isLogin">
					<view class="tu_center">
						<view class="wen" style="overflow: hidden;width: 100%;">
							<text class="yihang" style="max-width: 85%;display: inline-block;float: left;">
								{{userinfo.name || userinfo.nickname || '未设置昵称'}}
							</text>
							<image v-if="huiyuan" src="https://static-1310167831.cos.ap-nanjing.myqcloud.com/uploads/20230616/0eae0d57cc1b899a72c3be5aeb6d1fe6.png" style="width: 40rpx;height: 40rpx;display: block;float: left;margin-top: 10rpx;margin-left: 10rpx;" mode=""></image>
						</view>
						<view v-if="userinfo.company_check==2 || userinfo.firm_user==1" @click="rukou1" style="font-size: 24rpx;color: #038CFE;width: 100%;line-height: 30rpx;" class="yihang">
							{{userinfo.company || ''}}
						</view>
						<view class="tiao">
							<u-line-progress :percentage="userinfo.degree2" activeColor="#5EC4C2" :showText="false" height='4'
								inactiveColor="主色"></u-line-progress>
						</view>
						<view  class="zi">
							<view style="line-height: 30rpx;">
								资料完成度{{userinfo.degree2 || 0}}%
							</view>
							<view v-if="userinfo.degree2<100 || !userinfo.degree2" style="line-height: 30rpx;">
								尽快完善资料，以便于更方便地开展业务
							</view>
						</view>
					</view>
					<view v-if="userinfo.degree2<100" class="tu_right" @click="xinxi">
						<text class="iconfont icon-xiangyou you"></text>
					</view>
				</view>
			</view>
		</view>
		<view class="prow30">
			<view class="fuwu">
				<view class="wd_fw">
					我的服务
				</view>
				<view class="box">
					<view @click="guanzhu" class="b_fw">
						<image src="../../static/my/follow.png" mode=""></image>
						<view>
							我的关注
						</view>
					</view>
					<view @click="shoucang" class="b_fw">
						<image src="../../static/my/collect.png" mode=""></image>
						<view>
							我的收藏
						</view>
					</view>
					<view @click="fensi" class="b_fw">
						<image src="../../static/my/fans.png" mode=""></image>
						<view>
							我的粉丝
						</view>
					</view>
					<view @click="hudong" class="b_fw">
						<image src="../../static/my/you-and-me.png" mode=""></image>
						<view>
							我的互动
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="prow30">
			<view class="chang">
				<view class="gong">
					常用工具
				</view>
				<template v-for="(item,index) in commonTools" >
					<view v-if="item.show" @click="toMyLink(item)" class="guang flex justify-between" :key="index">
						<view class="flex items-center">
							<image :src="item.icon" class="imag" mode=""></image>
							<view class="wenzi">
								{{item.text}}
							</view>
						</view>
						<text class="iconfont icon-xiangyou tui"></text>
					</view>
				</template>
			</view>
		</view>

		<uni-popup id="popup" ref="popup" :type="type_status" :animation="true">
			<view class="" style="background-color: #FFFFFF;padding:20upx 30upx 0;border-radius: 20upx;width: 500rpx;">
				<view
					style="text-align: center;height: 100upx;line-height: 100upx;color: #333333;font-weight: 600;font-size: 32rpx;">
					提示
				</view>
				<view class="popup-content" style="text-align: center;font-size: 28upx;">请授权您的用户信息</view>
				<view class="footer">
					<button @click="quxiao"
						style="flex: 1;background-color: #f3f3f3;color: #333333;margin-right: 20rpx;font-weight: 600;"
						type="default">取消</button>
					<button @click="login" lang="zh_CN" style="flex: 1;background-color: #000000;color: #FFFFFF;"
						open-type="getUserInfo">确定</button>
					<!-- <button @click="submitLink" type="default" class="submit">确认提交</button> -->
				</view>
			</view>
		</uni-popup>
		<mrhardTabbar  :newsNum="xiaoxi_num"></mrhardTabbar>
		<noLoginToast ref="noLoginToast"/>
		<model ref="model"/>
	</view>
</template>

<script>
import {
  validateNull
} from '@/common'
import isAuditIos from '@/common/isAuditIos.js'
	import mrhardTabbar from "../../components/mrhard-tabbar.vue";
	import uPopup from '@/node_modules/uview-ui/components/u-popup/u-popup.vue'
	export default {
		components: {
			mrhardTabbar,
			uPopup
		},
		mixins: [isAuditIos],
		data() {
			return {
				isLogin: false,
				myBgSrc: require('@/static/my/my-bg.png'),
				myBgSrc1: require('@/static/my/member-bg.png'),
				logo: 'https://static-1310167831.cos.ap-nanjing.myqcloud.com/uploads/20230411/0b6303358a2cfb6ba9a45d4572d188cd.png',
				type_status:'center',
				userinfo:{},
				huiyuan:false,
				chat_look:'',
				xiaoxi_num:'',
				commonTools: [
					{type:'companyAccount',show:true,text: '升级为企业账号', icon: require('@/static/my/my1.png'), link: '/subpages/pages/fei_yuangong'},
					{type:'plan',show:false,text: '推广计划', icon: require('@/static/my/my2.png'), link: '/sub/pages/my/promotionPlan/index'},
					{type:'post',show:true,text: '我的发布', icon: require('@/static/my/my3.png'), link: '/sub/pages/my/wdfb'},
					{type:'post',show:true,text: '我的入驻市场', icon: require('@/static/my/my_master.png'), link: '/subpages/pages/rzsc'},
					{type:'order',show:false,text: '我的订单', icon: require('@/static/my/my_order.png'), link: '/sub/pages/my/myOrder/index'},
					{type:'block',show:true,text: '我的黑名单', icon: require('@/static/my/my4.png'), link: '/sub/pages/my/hei'},
					{type:'notice',show:true,text: '订阅通知', icon: require('@/static/my/my5.png'), link: '/sub/pages/my/subscriptionNotice/index'},
					{type:'customer',show:true,text: '联系客服', icon: require('@/static/my/my6.png'), link: '/sub/pages/my/gywm'},
					{type:'setting',show:true,text: '设置', icon: require('@/static/my/my7.png'), link: '/sub/pages/my/setting'},
					{type:'coupons',show:false,text: '优惠券', icon: require('@/static/my/my1.png'), link: '/sub/pages/my/wdyhq'},
					{type:'help',show:false,text: '帮助中心', icon: require('@/static/my/my1.png'), link: '/sub/pages/my/bzzx'}
				],
				show:true,
				pingguo_xian: true,
				iosUpAppStore: false
			}
		},
		onReady() {
			let token = uni.getStorageSync('token')
			if (validateNull(token)) {
				this.$refs.noLoginToast && this.$refs.noLoginToast.open()
			}
			uni.hideLoading();
		},
		onShow() {
			// this.iosUpAppStore = uni.getStorageSync('iosUpAppStore') ? false : true
			let token = uni.getStorageSync('token')
			if (token) {
				this.isLogin = true
				let userinfo = uni.getStorageSync('userinfo')
				if (userinfo) {
					this.userinfo = userinfo
				}
				this.user()
				this.xiaoxi_num=uni.getStorageSync('xiaoxi_num')
			}else {
				uni.setStorageSync('xiaoxi_num', 0)
				this.xiaoxi_num = 0
				this.isLogin = false
				this.huiyuan = false
				this.emptyUser()
			}
		},
		onLoad() {
		},
		methods: {
			emptyUser(){
				this.userinfo = ''
			},
			pingguo(){
				let that=this
				uni.getSystemInfo({
					    success: function (res) {
							let str = res.model
							that.post('api/index/wechat_check','',false).then(re=>{
								if(re.data==1){
									that.pingguo_xian=true
								}else{
									that.pingguo_xian=false
								}
							})
					  }
					});
			},
			// 开通会员
			async vip() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					if(this.userinfo.degree===100){
						if(this.userinfo.is_vip==1){
							uni.navigateTo({
								url:'../../subpages/pages/vip?is_vip=1'
							})
						}else{
							uni.navigateTo({
								url:'../../subpages/pages/vip?is_vip=0'
							})
						}
					}else{
						this.$refs.model.open()
					}
				}
			},
			// 用户信息
			async user_xx() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					if(this.userinfo.degree===100){
						uni.navigateTo({
							url: '../../subpages/pages/xgmp?isUserInfo=1'
						})
					}else{
						uni.navigateTo({
							url:'../../subpages/pages/xgmp?isUserInfo=2'
						})
					}
				}
			},
			loginSuccess() {
				this.user()
			},
			// 获取用户信息
			user() {
				this.post('api/client/info', '', false).then(res => {
					if (res.code == 1) {
						this.chat_look=res.data.chat_look
						this.userinfo=res.data
						uni.setStorageSync('is_push_follow',res.data.is_push_follow)
						uni.setStorageSync('is_push_msg',res.data.is_push_msg)
						uni.setStorageSync('is_push_news',res.data.is_push_news)
						if(res.data.is_vip!=0){
							this.huiyuan=true
						}else{
							this.huiyuan=false
						}
						// uni.setStorageSync('userinfo',
						// 	res.data)
						// uni.setStorageSync('mobile',
						// 	res.data.mobile)
					} else if(res.code==401){
						uni.removeStorageSync('token')
						uni.removeStorageSync('userinfo')
						uni.removeStorageSync('mobile')
						this.userinfo = ''
					}
				})
			},
			denglu:function(){
				this.$refs.noLoginToast.open()
			},
			// 完善信息
			async xinxi() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					if(this.userinfo.degree<100){
						uni.navigateTo({
							url: '../../subpages/pages/xgmp?isUserInfo=1'
						})
					}else{
						uni.navigateTo({
							url:'../../subpages/pages/xgmp?isUserInfo=1'
						})
					}
				}
			},
			// 签到
			async qiandao() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/qiandao'
					})
				}
			},
			// 收藏
			async shoucang() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/shoucang'
					})
				}
			},
			// 我的入驻市场
			async my_rzsc() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/rzsc'
					})
				}
			},
			// 我的关注
			async guanzhu() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/wdgz'
					})
				}
			},
			// 订阅通知
			async dingyue() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/dingyue'
					})
				}
			},
			lianxi:function(){
				uni.navigateTo({
					url:'/sub/pages/my/gywm'
				})
			},
			// 帮助中心
			bzzx: function() {
				uni.navigateTo({
					url: '/sub/pages/my/bzzx'
					// url:'../../subpages/pages/keduchi'
				})
			},
			// 我的发布
			async fabu() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/wdfb'
					})
				}
			},
			// 我的互动
			async hudong() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/wdhd'
					})
				}
			},
			// 我的粉丝
			async fensi() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/wdfs'
					})
				}
			},
			// 我的黑名单
			async hei() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/hei'
					})
				}
			},
			// 我的优惠券
			async wdyhq() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					uni.navigateTo({
						url: '/sub/pages/my/wdyhq'
					})
				}
			},
			async toMyLink(item) {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					if (item.type === 'order') {
						uni.navigateTo({
							url: item.link + '?is_vip=' + this.userinfo.is_vip
						})
					} else if (item.type === 'companyAccount') {
						this.rukou()
					} else {
						uni.navigateTo({
							url: item.link
						})
					}
				}
			},
			async qiye() {
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					this.post('api/client/info', '', true).then(res => {
						if(res.code==1){
							if(res.data.degree<100){
								this.$refs.model.open()
							}else{
								uni.navigateTo({
									url: '../../subpages/pages/qy_leibie'
								})
							}
						}
					})
				}
			},
			rukou:function(){
				if (uni.getStorageSync('token') == '' || uni.getStorageSync('token') == null) {
					this.$refs.popup.open()
					return
				}
				if(this.userinfo.company_check!=2){
					if(this.userinfo.firm_user==1){
						uni.navigateTo({
							url:'/subpages/pages/yuangong?fid='+this.userinfo.firm_id
						})
					}else{
						uni.navigateTo({
							url:'/subpages/pages/fei_yuangong'
						})
					}
				}else{
					uni.navigateTo({
						url:'/subpages/pages/shopjia'
					})
				}
			},
			async rukou1(){
				if (uni.getStorageSync('token') == '' || uni.getStorageSync('token') == null) {
					this.$refs.popup.open()
					return
				}
				let id = ''
				if (+this.userinfo.company_check===2) {
					let {code, data} = await this.post('api/firm/info','',false)
					if (+code === 1) {
						id = data.id
					}
				} else {
					id = this.userinfo.firm_id
				}
				if(+this.userinfo.special_type===1){
					uni.navigateTo({
						url: '../../fenbao/pages/wenzhang/qyxq?id=' + id +'&name='+this.userinfo.company
					})
				}else{
					uni.navigateTo({
						url:'../../subpages/pages/wuliuqiye/wl_qyxq?id='+id+'&name='+this.userinfo.company
					})
				}

			},
			async rukou1111(){
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					// company_check 这个字段我看代码是：1=企业待认证，2=认证通过，0=认证拒绝
					// firm_user  是否是企业绑定员工   1=已绑定，2=未绑定 0审核中
					if(this.userinfo.company_check!=2){
						if(this.userinfo.firm_user==1){
							this.$u.toast('您已绑定企业，无需再次认证')
							return
							// uni.navigateTo({
							// 	url:'/subpages/pages/yuangong?fid='+this.userinfo.firm_id
							// })
						}else{
							uni.navigateTo({
								url:'/subpages/pages/fei_yuangong'
							})
						}
					}else{
						uni.navigateTo({
							url:'/subpages/pages/shopjia'
						})
					}
				}
			},
			async rukou2222(){
				let isLogin = await this.$refs.noLoginToast.open()
				if (isLogin) {
					if(this.userinfo.special_type==1){
						uni.navigateTo({
							url: '../../fenbao/pages/wenzhang/qyxq?id=' + this.userinfo.firm_id+'&name='+this.userinfo.company
						})
					}else{
						uni.navigateTo({
							url:'../../subpages/pages/wuliuqiye/wl_qyxq?id='+this.userinfo.firm_id+'&name='+this.userinfo.company
						})
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #F8F8F8 !important;
		padding-bottom: 200rpx;
		font-family: Demibold;
	}
	.footer {
		display: flex;
		justify-content: space-between;
		border-top: 1px solid #f4f4f4;
		margin-top: 30rpx;
		padding-bottom: 20rpx;

		button {
			margin: 0 auto;
			width: 100%;
			background-color: #19BE6B;
			// width: 200upx;
			border-radius: 10upx;
			font-size: $uni-font-size-sm;
			// padding: 22upx 34upx;
			height: 80upx;
			font-size: 30rpx;
			line-height: 80upx !important;
			// line-height: 1;
			color: #FFFFFF;
		}

		button:after {
			border: 0;
		}
	}
	.my_container {
		padding-top: 530rpx;
	}
	.bg {
		position: relative;
		z-index: 99;
		height: 530rpx;
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
	}

	.da {
		width: 660rpx;
		height: 122rpx;
		position: absolute;
		position: absolute;
		left: 50%;
		bottom: 8rpx;
		transform: translateX(-50%);
	}

	.hei {
		width: 660rpx;
		height: 122rpx;
	}

	.vip {
		width: 48rpx;
		height: 48rpx;
		position: absolute;
		left: 24rpx;
		top: 12rpx;
	}

	.kai {
		color: #FFFFFF;
		font-size: 20rpx;
		position: absolute;
		left: 24rpx;
		top: 64rpx;
		opacity: 0.6;
	}

	.liji {
		width: 124rpx;
		height: 50rpx;
		background: linear-gradient(-90deg, #DAAB6C 0%, #F3CE9C 100%);
		border-radius: 25rpx;
		line-height: 50rpx;
		text-align: center;
		position: absolute;
		right: 38rpx;
		top: 50%;
		transform: translateY(-50%);
		color: #411C0C;
		font-size: 20rpx;
	}

	.wdbg {
		width: 100%;
		height: 530rpx;

	}

	.tu {
		width: 660rpx;
		margin: 0 auto;
		overflow: hidden;
		position: absolute;
		top: 200rpx;
		left: 50%;
		transform: translateX(-50%);
	}

	.tu_left {
		float: left;
		width: 120rpx;
		height: 120rpx;
		border-radius: 50%;
		background-color: #f6f6f6;
		z-index: 100;
		position: relative;
	}

	.avatar {
		width: 120rpx;
		height: 120rpx;
		display: block;
		border-radius: 50%;
		overflow: hidden;
	}

	.tu_center {
		float: left;
		width: 65%;
		margin-left: 26rpx;
		padding-top: 14rpx;
	}

	.wen {
		line-height: 60rpx;
		color: #000000;
		font-size: 36rpx;
		font-weight: 600;
	}

	.tiao {
		margin-top: 16rpx;
	}

	.zi {
		color: #666;
		font-size: 22rpx;
		margin-top: 10rpx;
	}

	.tu_right {
		float: left;
	}

	.you {
		position: absolute;
		top: 40rpx;
		right: 0;
		color: #999999;
	}



	.fuwu {
		width: 100%;
		background-color: #FFFFFF;
		box-sizing: border-box;
		padding: 20rpx 28rpx 40rpx;
		position: relative;
		border-bottom-left-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
	}

	.wd_fw {
		line-height: 100rpx;
		color: #000;
		font-size: 32rpx;
		position: absolute;
		padding: 50rpx 30rpx 0;
		top: -40rpx;
		left: 0rpx;
		background-color: #FFFFFF;
		width: 100%;
		font-weight: 600;
		box-sizing: border-box;
	}

	.box {
		display: flex;
		margin-top: 100rpx;
	}

	.b_fw {
		flex: 1;
		text-align: center;
	}

	.b_fw image {
		width: 62rpx;
		height: 62rpx;
	}

	.b_fw view {
		color: #262d2c;
		font-size: 28rpx;
		line-height: 34rpx;
	}


	.chang {
		width: 100%;
		margin: 30rpx 0;
		box-sizing: border-box;
		padding: 10rpx 28rpx 20rpx;
		background-color: #FFFFFF;
		border-radius: 20rpx;
	}

	.gong {
		line-height: 80rpx;
		color: #000;
		font-size: 32rpx;
		font-weight: 400;
	}

	.guang {
		line-height: 100rpx;
		position: relative;
		padding-left: 60rpx;
		height: 100rpx;
		// box-sizing: border-box;
	}

	.imag {
		width: 40rpx;
		height: 40rpx;
		position: absolute;
		top: 50%;
		left: 0;
		transform: translateY(-50%);
	}

	.wenzi {
		color: #333;
		font-size: 28rpx;
	}

	.tui {
		color: #999999;
		float: right;
	}
</style>
